'''
要识别客户时，可以用requests中自动管理cookie的机制来发送请求。
创建一个session，用session发送请求，会自动管理cookie
'''

import requests

# requests.get  / post
s = requests.session()  # 创建一个session

print("登录之前的cookie：", s.cookies)

# 登录，服务器响应的信息中包含了 set-cookie
cs = {"access_type": "1",
      "loginType": "1",
      "emailLoginWay": "0",
      "account": "2780487875@qq.com",
      "password": "qq2780487875",
      "remindmeBox": "on",
      "remindme": "1"}
r = s.post("https://www.bagevent.com/user/login", data=cs)  # 用session发送
# print(r.text)

print("登录之后的cookie：", s.cookies)

# dashboard， 请求中会带上cookie，
r = s.get("https://www.bagevent.com/account/dashboard")
# print(r.text)
print(r.request.headers)
assert "<title>百格活动 - 账户总览</title>" in r.text

# 请求时没有带着cookie，没有用户的登录状态
r = requests.get("https://www.bagevent.com/account/dashboard")
# assert  "<title>百格活动 - 账户总览</title>" in r.text
print(r.request.headers)

# r = s.get("https://www.bagevent.com/user/login_out")
# print("退出登录之后的cookie：", s.cookies)
